package com.example.post.services.impl;

import com.example.post.mapper.BookmarkMapper;
import com.example.post.model.Blog;
import com.example.post.model.Bookmark;
import com.example.post.model.Result;
import com.example.post.services.BookmarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookmarkServiceImpl implements BookmarkService {
        @Autowired
     BookmarkMapper bookmarkMapper;

    @Autowired
    public BookmarkServiceImpl(BookmarkMapper bookmarkMapper) {
        this.bookmarkMapper = bookmarkMapper;
    }

    @Override
    public void addBookmark(Bookmark bookmark) {
        bookmarkMapper.addBookmark(bookmark);
    }
    @Override
    public void deleteBookmark(int blogId) {
        bookmarkMapper.deleteBookmark(blogId);
    }
    @Override
    public Result checkBookmark(int bookmarkId) {
        boolean isBookmarked = bookmarkMapper.checkBookmark(bookmarkId);
        Result result;
        if (isBookmarked) {
            result = new Result(100);
        } else {
            result = new Result(200);
        }
        return result;
    }

    @Override
    public List<Blog> getBookmarksByUserId(int userId) {
        return bookmarkMapper.getBookmarksByUserId(userId);
    }


}
